<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../css/common.css">
<link rel="stylesheet" href="../css/main.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../../layer/layer.js"></script>
</head>
<body>
	<div id="forms" class="mt10">
		<div class="box">
			<div class="box_border">
				<div class="box_center">
					<form id="myform">
						姓名：<input type="text" id="tname" class="input-text lh30" size="40" />&emsp;
						密码：<input type="password" id="pwd" class="input-text lh30" size="40" />&emsp; 
						手机号码：<input type="tel" id="tel" class="input-text lh30" size="40" />&emsp; 
						<input type="button" name="button" class="btn btn82 btn_save2" onclick="addMenberInfo()" value="添加" />&emsp;
					</form>
				</div>
			</div>
		</div>
	</div>

	<div id="table" class="mt10">
		<div class="box span10 oh">
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
				class="list_table">
				<thead>
					<tr>
						<th width="20%">编号</th>
						<th width="30%">姓名</th>
						<th width="30%">联系方式</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="admin_info" align="center">
					<tr>
						<td width="20%">编号</td>
						<td width="30%">姓名</td>
						<td width="30%">联系方式</td>
						<td>操作</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</body>

<script type="text/javascript">
$(function(){
	findByAll();
});

function findByAll() {
	$.get("../../admin/findAll", function(data){
		console.log(data);
		var str = "";
		$.each(data, function(index, item) {
			str += "<tr><td>"+item.aid+"</td><td>"+item.aname+"</td><td>"+item.tel+"</td><td><a href='javascript:resetPwd("+item.aid+")'>"
			str += "[重置密码]&emsp;</a><a href='javascript:del("+item.aid+")'>[删除]</a></td></tr>";
		});
		$("#admin_info").html("").append($(str));
	},"json");
}

//function createTable(data,  )

function addMenberInfo(){
	var aname=$.trim( $("#tname").val() );
	var pwd=$.trim( $("#pwd").val() );
	var tel=$.trim( $("#tel").val() );
	
	if (aname == "") {
		layer.alert("请输入管理员姓名...",{icon:2});
		return;
	}
	if (pwd == "") {
		layer.alert("请输入管理员密码...",{icon:2});
		return;
	}
	if (tel == "") {
		layer.alert("请输入管理员手机号码...",{icon:2});
		return;
	}
	
	$.post("../../admin/add", {aname:aname, pwd:pwd, tel:tel}, function(data){
		data = parseInt($.trim(data));
		if (data > 0) {
			$("#myform")[0].reset();
			findByAll();
			layer.msg('添加成功...');
		} else {
			layer.alert("管理员信息添加失败，请稍后重试...",{icon:5});
		}
	},"text");
}

function resetPwd(aid) {
	$.post("../../admin/updatePwd", {aid:aid}, function(data){
		data = parseInt($.trim(data));
		if (data > 0) {
			layer.msg("管理员密码已成功重置为手机号码后 6 位...");
		} else {
			layer.alert("管理员密码重置失败...",{icon:5});
		}
	},"text");
}

//*****删除管理员****************/
function del(aid){
	$.post("../../admin/delByAid",{aid:aid},function(data){
		data = parseInt($.trim(data));
		if(data > 0){
			findByAll();
			layer.msg("删除成功！");
		}else{
			layer.msg("删除失败！");
		}
	});
}
</script>
</html>